package com.gl.goods.ui.splash.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.gl.goods.R;
import com.gl.goods.base.HXYXConstant;
import com.gl.goods.ui.login.activity.LoginActivity;
import com.gl.goods.ui.main.activity.MainActivity;
import com.gl.goods.ui.splash.FileUtil;
import com.gl.library.tool.RxBarTool;
import com.gl.library.tool.RxSPTool;
import com.gl.library.widget.view.AnimLogoView;

/**
 *@description:启动页
 */
public class SplashActivity extends AppCompatActivity {

    private AnimLogoView animLogoView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        /**
         * 隐藏状态栏并全屏
         */
        RxBarTool.hideStatusBar(this);
        super.onCreate(savedInstanceState);
        /**
         * 如果不是第一次启动app，则正常显示启动屏
         */

        setContentView(R.layout.activity_splash);
        animLogoView = findViewById(R.id.anim_logo);
        /**
         * 判断是否是第一次开启应用
         */
        boolean isFirstOpen = RxSPTool.getBoolean(this, HXYXConstant.FIRST_OPEN);
        /**
         * 如果是第一次启动，则先进入功能引导页
         */
        animLogoView.addGradientAnimListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (!isFirstOpen) {
                    enterLoginActivity();
                } else {
                    /**
                     * 两秒后进入首页
                     */
                    enterHomeActivity();
                }
            }
        });


        animLogoView.startAnimation();
    }

    /**
     *@description:进入登录页
     */
    private void enterLoginActivity() {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.putExtra("type","splash");
        startActivity(intent);
        finish();
    }

    /**
     *@description:进入首页
     */
    private void enterHomeActivity() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
